<?php
C_base::Dy('c.kefu.kfbase');
class news extends kfbase{
	
	var $_vpath='kefu/news/';  //定义调用模板所属一级文件夹
	function __construct(){
		parent::__construct();
		$this->title='新闻管理';
	}
	
	function index(){//页面-新闻管理
		$this->title = '新闻管理';
		$this->xw = C_base::M('kefu.news')->news_ss(array());
		$this->xwnum = count($this->xw);
	}
	
	function add_news(){//页面-添加新闻
		$this->title = '添加新闻';
	}
	
	function news_c(){//添加新闻
		$this->_is_html = 1;
		extract($this->_post());
		if(@empty($title)){
			exit('-1');//标题不能为空
		}
		if(@empty($content)){
			exit('-2');//内容不能为空
		}
		C_base::dybase('util')->zfpd($title,'40','标题不能大于40个字符!','2');
		C_base::dybase('util')->zfpd($content,'3','内容不能小于3个字符!','1');
		$c = array('title'=>$title,'zuozhe'=>$zuozhe,'content'=>htmlspecialchars($content),'time'=>time());
		$r = C_base::M('kefu.news')->news_c($c);
		if($r > 0){
			exit('cg');//添加成功
		}else{
			exit('error');//添加失败
		}
	}
	
	function xiu_news(){//页面-新闻修改
		$this->xw = C_base::M('kefu.news')->news_s(array('id'=>$this->_get('id')));
		$this->xw['content'] = htmlspecialchars_decode($this->xw['content']);
	}

	function news_u(){//新闻修改
		$this->_is_html = 1;
		extract($this->_post());
		if(@empty($title)){
			exit('-1');//标题不能为空
		}
		if(@empty($content)){
			exit('-2');//内容不能为空
		}
		C_base::dybase('util')->zfpd($title,'40','标题不能大于40个字符!','2');
		C_base::dybase('util')->zfpd($content,'3','内容不能小于3个字符!','1');
		$w = array('id'=>$id);
		$u = array('title'=>$title,'zuozhe'=>$zuozhe,'content'=>htmlspecialchars($content));
		$r = C_base::M('kefu.news')->news_u($w,$u);
		if($r == '1'){
			exit('cg');//修改成功
		}else{
			exit('error');//修改失败
		}
	}
	
	function news_d(){//新闻删除
		$this->_is_html = 1;
		extract($this->_post());
		if(empty($id)){
			exit('error');//删除失败
		}
		$w = array('id'=>$id);
		$r = C_base::M('kefu.news')->news_s($w);
		if($r){
			$rr = C_base::M('kefu.news')->news_d($w);
			if($rr == '1'){
				exit('cg');//删除成功
			}else{
				exit('error');//删除失败
			}
		}
	}
	
	function news_ds(){//新闻删除(多选)
		$this->_is_html = 1;
		extract($this->_post());
		$sc = array_filter(explode(',',$xi));//所选择的新闻id
		if(!$sc){
			exit('-1');//请选择新闻后再进行操作
		};
		$arr = 0;
		foreach($sc as $k => $v){
			$w = array('id'=>$v);
			$r = C_base::M('kefu.news')->news_s($w);
			if($r){
				$rr = C_base::M('kefu.news')->news_d($w);
				if($rr == '1'){
					$arr = 1;
				}
			}
		}
		if($arr == 1){
			exit('cg');//删除成功
		}else{
			exit('error');//删除失败
		}
	}
	
	function news_tj(){//推荐
		$this->_is_html = 1;
		extract($this->_post());
		if(empty($id)){
			exit('-1');//修改失败
		}
		$w = array('id'=>$id);
		$r = C_base::M('kefu.news')->news_s($w);
		if($r){
			if($r['tj'] == '1'){
				$u = array('tj'=>0);
			}else{
				$u = array('tj'=>1);
			}
			$rr = C_base::M('kefu.news')->news_u($w,$u);
			if($rr == '1'){
				exit('cg');//修改成功
			}else{
				exit('error');//修改失败
			}
		}
	}
}
/*********************************************************************文件已结束*****************************************************************/